package com.shizhanzhe.zxbapp.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.shizhanzhe.zxbapp.R;


/**
 * Created by YJ on 2018/10/15.
 */
public class PhotoDialog extends Dialog {

    private PhotoListener mPhotoListener;
    private TextView tv_camera;
    private TextView tv_photo;
    private TextView tv_close;

    public void setPhotoListener(PhotoListener photoListener) {
        mPhotoListener = photoListener;
    }

    public PhotoDialog(@NonNull Context context) {
        super(context, R.style.my_dialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (null != getWindow()){
            getWindow().setGravity(Gravity.BOTTOM);
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.dimAmount = 0.5f;
            getWindow().setAttributes(lp);
        }
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        setContentView(R.layout.dialog_photo);
        tv_camera = findViewById(R.id.tv_camera);
        tv_photo = findViewById(R.id.tv_photo);
        tv_close = findViewById(R.id.tv_close);
        tv_camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPhotoListener.chooseCamera();
            }
        });
        tv_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPhotoListener.choosePhoto();
            }
        });
        tv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPhotoListener.chooseClose();
            }
        });

        setCanceledOnTouchOutside(true);
    }
    @Override
    public void dismiss() {
        super.dismiss();
    }

    public interface PhotoListener{
        void chooseCamera();
        void choosePhoto();
        void chooseClose();
    }
}
